<?php
declare (strict_types = 1);
namespace app\course\logic\base\admin;

use app\course\model\base\CourseSection as CourseSectionModel;

/**
 * 课程课时数据
 */
class CourseSection extends CourseSectionModel
{

    /**
     * 解析课时信息
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date：   2020-05-08
     */
    public function parseCourseHour($sec)
    {
        $type           = $sec->product_key;
        $course_data_id = $sec->getAttr('course_data_id');
        $classname      = '\\app\\course\\model\\' . $type . '\\CourseSection' . ucfirst($type);
        $section_data   = new \ArrayObject();

        if (class_exists($classname) && $course_data_id > 0) {
            $data         = app($classname)->where('id', $course_data_id)->findOrEmpty();
            $section_data = !$data->isEmpty() ? $data : $section_data;
        }

        return $section_data;
    }

}
